import request from '../request';
import {
  BUY_COMMODITY_REQ,
  GET_DISCOVERY_PAGE_REQ,
  CHECK_BUY_COMMODITY_RESULT_REQ,
  GET_USER_COURSE_PAGE_REQ,
  GET_COMMODITY_DETAIL_REQ,
  USER_GET_LESSON_RESOURCE_IDS_REQ
} from '../../service/constant';
import {
  BuyCommodityParams,
  GetDiscoveryPageParams,
  CheckBuyCommodityResultParams,
  GetCommodityDetailParams
} from './paramsInterface';
import { GetDiscoveryPageRes } from './getDiscoveryPage';
import { BuyCommodityRes } from './buyCommodity';
import { CheckBuyCommodityResultRes } from './checkBuyCommodityResult';
import { GetUserCoursePageRes } from './getUserCoursePage';
import { GetCommodityDetailRes } from './getCommodityDetail';
import { GetLessonResourceIDsRes } from './getLessonResourceIDs';

export default {
  // 获取发现页
  getDiscoveryPage: (
    data: GetDiscoveryPageParams
  ): Promise<GetDiscoveryPageRes> =>
    request({
      msgId: GET_DISCOVERY_PAGE_REQ,
      data
    }),
  // 购买商品
  buyCommodity: (data: BuyCommodityParams): Promise<BuyCommodityRes> =>
    request({
      msgId: BUY_COMMODITY_REQ,
      data,
      param: { needLoading: true }
    }),
  // 获取购买商品结果
  checkBuyCommodityResult: (
    data: CheckBuyCommodityResultParams
  ): Promise<CheckBuyCommodityResultRes> =>
    request({
      msgId: CHECK_BUY_COMMODITY_RESULT_REQ,
      data,
      param: { needLoading: true }
    }),
  // 获取个人课程列表页
  getUserCoursePage: (needLoading?: boolean): Promise<GetUserCoursePageRes> =>
    request({
      msgId: GET_USER_COURSE_PAGE_REQ,
      param: { needLoading: !!needLoading }
    }),
  // 获取商品详情
  getCommodityDetail: (
    data: GetCommodityDetailParams
  ): Promise<GetCommodityDetailRes> =>
    request({
      msgId: GET_COMMODITY_DETAIL_REQ,
      data
    }),
  // 用户获取教案ID
  getLessonResourceIDs: (): Promise<GetLessonResourceIDsRes> =>
    request({
      msgId: USER_GET_LESSON_RESOURCE_IDS_REQ
    })
};
